package com.open.party.cloud.viewModel;

import cn.android.x.model.data.AppPageData
import cn.android.x.model.data.PageReq
import cn.android.x.model.data.ResultInfo
import com.open.party.cloud.ServerConfig
import com.open.party.cloud.model.CommVo
import com.open.party.cloud.model.JiFenBean
import com.open.party.cloud.model.data.Api
import com.sinothk.rxretrofit.RxRetrofit
import org.greenrobot.eventbus.EventBus
import rx.Subscriber
import rx.android.schedulers.AndroidSchedulers
import rx.schedulers.Schedulers


class JiFenViewModel {

    fun getJiFenPageListForMeData(pageReq: PageReq<CommVo>) {

        RxRetrofit.init(ServerConfig.SERVER_URL, ServerConfig.getHeader())
            .create(Api::class.java)
            .getJiFenPageListForMeData(pageReq)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(object : Subscriber<ResultInfo<AppPageData<JiFenBean>>>() {

                override fun onCompleted() {}

                override fun onError(e: Throwable) {
                    val result = ResultInfo<AppPageData<JiFenBean>>(ResultInfo.ERROR, ResultInfo.getErrorMsg(e.message))
                    result.eventType = "getJiFenPageListForMeData"
                    EventBus.getDefault().post(result)
                }

                override fun onNext(result: ResultInfo<AppPageData<JiFenBean>>) {
                    result.eventType = "getJiFenPageListForMeData"
                    EventBus.getDefault().post(result)
                }
            })
    }
}
